package fifth.utils;

import com.alibaba.druid.pool.DruidDataSource;
import com.alibaba.druid.pool.DruidDataSourceFactory;

import javax.sql.DataSource;
import java.io.InputStream;
import java.util.Properties;

public class DataSourceUtils {

    private static DruidDataSource dataSource;
    static {
        //加载配置文件
        try {
            InputStream is=DataSourceUtils.class.getClassLoader().getResourceAsStream("druid.properties");
            Properties properties=new Properties();
            properties.load(is);
            dataSource= (DruidDataSource) DruidDataSourceFactory.createDataSource(properties);
        } catch (Exception e) {
            e.printStackTrace();
            System.out.println("初始化连接池失败");
        }
    }

    public static DataSource getDataSource(){
        return  dataSource;
    }

}
